package com.company.Stack;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:48
 */
public class ArrayStackDemo {
    public static void main(String[] args) {
        ArrayStack arrayStack = new ArrayStack(5);
        arrayStack.pushStack(4);
        arrayStack.pushStack(2);
        arrayStack.pushStack(3);
        arrayStack.pushStack(6);
        arrayStack.pushStack(0);
        arrayStack.popStack();

    }

    static class ArrayStack{
        private int MaxTop;//栈的大小；
        private int[] stack;
        private int top = -1;

        //确定栈的上限
        public ArrayStack(int maxTop) {
            MaxTop = maxTop;
            stack = new int[maxTop];
        }

        //判断是否为空
        public void isEmpty(){
            if (top==-1){
                throw new RuntimeException("栈为空");
            }
        }

        //判断是否满栈
        public void isFull(){
            if (top==MaxTop){
                throw new RuntimeException("栈已满");
            }
        }

        //压栈
        public void pushStack(int value){
//            isEmpty();
            isFull();
            top++;
            stack[top] = value;
        }

        //出栈
        public void popStack(){
            isEmpty();
            while (top!=-1) {
                int value = stack[top];
                System.out.println("出栈的为" +top+"节点："+ value);
                top--;
            }
        }
    }

}
